﻿@model FieldControlViewModel
@{
	string jsonData = string.Empty;
	string[] separator = new string[] { "$$$" };
	string[] selectItem = Model.Settings[0].Split(separator, StringSplitOptions.RemoveEmptyEntries);
	string dataVal = string.Empty;
	string dataValMsg = string.Empty;
	if (Model.EnableNull)
	{
		dataVal += " data-val-required=\"不能为空\" ";
	}
	if (!string.IsNullOrEmpty(dataVal))
	{
		dataVal += " data-val=\"true\" ";
		dataValMsg = " data-valmsg-for=\"" + Model.Prefix + Model.FieldName + "\" data-valmsg-replace=\"true\"";
	}
	switch (Model.Settings[1])
	{
		case "1"://单选下拉框
		case "2"://多选下拉框
			foreach (string item in selectItem)
			{
				string jsonItemData = string.Empty;
				string[] arrItem = item.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
				if (arrItem.Length > 1)
				{
					jsonItemData = "{id:'" + arrItem[1] + "',text:'" + arrItem[0] + "'}";
				}
				else
				{
					jsonItemData = "{id:'" + arrItem[0] + "',text:'" + arrItem[0] + "'}";
				}
				jsonData += jsonItemData + ",";
			}
			jsonData = jsonData.TrimEnd(',');
			jsonData = "[" + jsonData + "]";
			<span class="select-box radius">
				<select class="layui-input" name="@Model.Prefix@Model.FieldName" id="@Model.Prefix@Model.FieldName" @Html.Raw(dataVal) lay-ignore></select>
			</span>
			break;
		case "3"://单选按纽
			for (int i = 0; i < selectItem.Length; i++)
			{
				string itemValue = string.Empty;
				string itemText = string.Empty;
				string[] arrItem = selectItem[i].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
				if (arrItem.Length > 1)
				{
					itemText = arrItem[0];
					itemValue = arrItem[1];
				}
				else
				{
					itemText = arrItem[0];
					itemValue = arrItem[0];
				}
				if (itemValue == Model.FieldValue)
				{
					<input type="radio" name="@Model.Prefix@Model.FieldName" value="@itemValue" title="@itemText" checked="checked">
				}
				else
				{
					<input type="radio" name="@Model.Prefix@Model.FieldName" value="@itemValue" title="@itemText">
				}
				if (i > 0 && i % Model.Settings[3].ToInt32() == 0)
				{
					<br />
				}
			}
			break;
		case "4"://复选框
			for (int i = 0; i < selectItem.Length; i++)
			{
				string itemValue = string.Empty;
				string itemText = string.Empty;
				string[] arrItem = selectItem[i].Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
				if (arrItem.Length > 1)
				{
					itemText = arrItem[0];
					itemValue = arrItem[1];
				}
				else
				{
					itemText = arrItem[0];
					itemValue = arrItem[0];
				}
				if (StringHelper.FoundCharInArr(Model.FieldValue,itemValue))
				{
					<input type="checkbox" name="@Model.Prefix@Model.FieldName" value="@itemValue" lay-skin="primary" title="@itemText" checked="checked">
				}
				else
				{
					<input type="checkbox" name="@Model.Prefix@Model.FieldName" value="@itemValue" lay-skin="primary" title="@itemText">
				}
				int index = i + 1;
				if (index % Model.Settings[3].ToInt32() == 0)
				{
					<br />
				}
			}
			break;
	}
}
<span class="layui-bg-green">@Model.Description</span>
<span style="color:red;" @Html.Raw(dataValMsg)></span>
@{
	if (Model.Settings[1] == "1" || Model.Settings[1] == "2")
	{
		<script type="text/javascript">
		function @{@Model.Prefix@Model.FieldName}InitListControl() {
			var showType = "@Model.Settings[1]";
			var selectID = "@Model.Prefix@Model.FieldName";
			var data = @Html.Raw(jsonData);
			var selectValue = "@Model.FieldValue";
			switch (showType) {
				case "1":
					initSelect2(selectID, data, selectValue, false);
					break;
				case "2":
					initSelect2(selectID, data, selectValue, true);
					break;
			}
		}
		jQuery(function () {
			@{@Model.Prefix@Model.FieldName}InitListControl();
		});
		</script>
	}
}
